package com.yipao.wx.service;

import com.yipao.db.domain.YipaoRegion;
import com.yipao.db.service.YipaoRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zhy
 * @date 2019-01-17 23:07
 **/
@Component
public class GetRegionService {

    @Autowired
    private YipaoRegionService regionService;

    private static List<YipaoRegion> YipaoRegions;

    protected List<YipaoRegion> getYipaoRegions() {
        if (YipaoRegions == null) {
            createRegion();
        }
        return YipaoRegions;
    }

    private synchronized void createRegion() {
        if (YipaoRegions == null) {
            YipaoRegions = regionService.getAll();
        }
    }
}
